import type { RouteRecordRaw } from 'vue-router'

const pageTitle = (name: string): string => {
  return `pagesTitle.${name}`
}

/*
 * 静态路由
 */
const staticRoutes: Array<RouteRecordRaw> = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue')
  },
  {
    // 首页
    path: '/',
    name: 'layout',
    component: () => import('@/views/layout/index.vue'),
    meta: {
      requireAuth: true
    },
    children: [
      {
        path: '',
        name: 'dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: {
          title: '控制台'
        }
      },
      {
        path: '/system',
        name: 'system',
        meta: {
          title: '系统设置'
        },
        children: [
          {
            path: '/systemIndex',
            name: 'systemIndex',
            component: () => import('@/views/system/index.vue')
          },
          {
            path: '/user',
            name: 'user',
            meta: {
              title: '用户管理'
            },
            component: () => import('@/views/system/user/index.vue')
          },
          {
            path: '/role',
            name: 'role',
            meta: {
              title: '角色管理'
            },
            component: () => import('@/views/system/role/index.vue')
          },
          {
            path: '/permission',
            name: 'permission',
            meta: {
              title: '权限管理'
            },
            component: () => import('@/views/system/permission/index.vue')
          },
          {
            path: '/report',
            name: 'report',
            meta: {
              title: '举报管理'
            },
            component: () => import('@/views/system/report/index.vue')
          }
        ]
      },
      {
        path: '/content',
        name: 'content',
        meta: {
          title: '内容管理'
        },
        children: [
          {
            path: '/contentIndex',
            name: 'contentIndex',
            component: () => import('@/views/content/index.vue')
          },
          {
            path: '/article',
            name: 'article',
            meta: {
              title: '物品管理'
            },
            component: () => import('@/views/content/article/index.vue')
          },
          {
            path: '/category',
            name: 'category',
            meta: {
              title: '分类管理'
            },
            component: () => import('@/views/content/category/index.vue')
          },
          {
            path: '/comment',
            name: 'comment',
            meta: {
              title: '评论管理'
            },
            component: () => import('@/views/content/comment/index.vue')
          }
        ]
      }
    ]
  },
  {
    path: '/:path(.*)*',
    redirect: '/404'
  },
  {
    // 404
    path: '/404',
    name: 'notFound',
    component: () => import('@/views/404.vue'),
    meta: {
      title: pageTitle('notFound') // 页面不存在
    }
  },
  {
    // 无权限访问
    path: '/401',
    name: 'noPower',
    component: () => import('@/views/401.vue'),
    meta: {
      title: pageTitle('noPower')
    }
  }
]
export { staticRoutes }
